package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.BreedFactoryStableDao;
import com.jiantong.user.model.BreedFactoryStable;
import com.jiantong.user.service.BreedFactoryStableWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by mz on 24/7/17.
 *
 */
@Slf4j
@RpcProvider
@Service
public class BreedFactoryStableWriteServiceImpl implements BreedFactoryStableWriteService{

    private final BreedFactoryStableDao breedFactoryStableDao;

    @Autowired
    public BreedFactoryStableWriteServiceImpl(BreedFactoryStableDao breedFactoryStableDao) {
        this.breedFactoryStableDao = breedFactoryStableDao;
    }

    @Override
    public Response<Long> create(BreedFactoryStable breedFactoryStable) {

        try {
            breedFactoryStableDao.create(breedFactoryStable);
            return Response.ok(breedFactoryStable.getId());
        }catch (Exception e){
            log.error("failed to add a stable for breed factory case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to add a stable for breed factory");
        }
    }

    @Override
    public Response<Boolean> update(BreedFactoryStable breedFactoryStable) {
        try{
            return Response.ok(breedFactoryStableDao.update(breedFactoryStable));
        }catch (Exception e){
            log.error("failed to update stable of breed factory case = {}",Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update stable of breed factory");
        }
    }

    @Override
    public Response<Boolean> delete(Long id) {

        try{
            return Response.ok(breedFactoryStableDao.delete(id));
        }catch (Exception e){
            log.error("failed to delete a stable of breed factory case = {}",Throwables.getStackTraceAsString(e));
            return Response.fail("failed to  delete stable of breed factory");
        }
    }
}


